locals {
  subnet_name = {
    dev-baidu_hub-devops           = "172.16.0.0/28"
    dev-baidu_hub-db-mysql         = "172.16.0.64/27"
    dev-baidu_hub-db-redis         = "172.16.0.96/27"
    dev-baidu_hub-db-mongodb       = "172.16.0.128/27"
    dev-baidu_hub-db-elasticsearch = "172.16.0.160/27"
    dev-baidu_hub-db-sfs           = "172.16.0.32/28"
    dev-baidu_hub-natgateway       = "172.16.0.16/28"
    dev-baidu_hub-cce-myapp     = "172.16.2.128/25"
    dev-baidu_hub-ecs-web          = "172.16.2.0/28"
    dev-baidu_hub-ecs-voip         = "172.16.3.128/25"
    dev-baidu_hub-ecs-miniapp      = "172.16.3.0/25"
    dev-baidu_hub-db-kafka         = "172.16.1.64/26"
    dev-baidu_hub-db-zookeeper     = "172.16.1.0/28"
    dev-baidu_hub-db-rabbitmq      = "172.16.1.128/26"
  }
}

data "terraform_remote_state" "vpc" {
  backend = "remote"
  config = {
    hostname : "baidu.jfrog.io"
    organization : "baidu-hub-terraform-state-dev"
    workspaces = {
      name : "ap-southeast-3-vpc-dev"
    }
  }
}


module "subnet" {
  source            = "../../../modules/subnet"
  for_each          = local.subnet_name
  subnet_name       = each.key
  subnet_cidr       = each.value
  subnet_gateway_ip = cidrhost(each.value, 1)
  ava_zone          = "${var.REGION}a"
  /* Use VPC create by Terraform */
  vpc_id = data.terraform_remote_state.vpc.outputs.vpc_info.id

  /*Use an Existing VPC*/
  /* vpc_id = "24f97844-2448-41a5-a486-a3436439f307" */
}
